/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.munchkinquest.beans;

import com.munchkinquest.Constants;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 * Manages Player statistics such as Movement count and Health
 * @author stephen
 */
@ManagedBean
@SessionScoped
public class Player {
    public static final int DEFAULT_HEALTH = 4;
    public static final int DEFAULT_MOVEMENT = 3;
    private boolean alreadyExitedRoomThisTurn = false;

    public boolean isDead() {
        return health == 0;
    }

    void reset() {
        movement = DEFAULT_MOVEMENT;
        health = DEFAULT_HEALTH;
        alreadyExitedRoomThisTurn = false;
    }

    private int movement = DEFAULT_MOVEMENT;
    private int health = DEFAULT_HEALTH;
    private int totalHealth = DEFAULT_HEALTH;
    private int totalMovement = DEFAULT_MOVEMENT;

    public void setHealth(int health) {
        this.health = health;
    }

    public void setMovement(int movement) {
        this.movement = movement;
    }

    public void setTotalHealth(int totalHealth) {
        this.totalHealth = totalHealth;
    }

    public void setTotalMovement(int totalMovement) {
        this.totalMovement = totalMovement;
    }

    public String getMovementList() {
        StringBuilder result = new StringBuilder("");
        result.append("<ul>");
        for (int i = 1; i <= movement; i++) {
            result.append("<li><img src=\""+Constants.FOOT_GREEN+"\"></li>");
        }
        for (int i = movement; i < totalMovement; i++) {
            result.append("<li><img src=\""+Constants.FOOT_RED+"\"></li>");
        }
        result.append("</ul>");
        return result.toString();
    }

    public int getTotalMovement() {
        return totalMovement;
    }

    public int getTotalHealth() {
        return totalHealth;
    }

    public String getHealthList() {
        StringBuilder result = new StringBuilder("");
        result.append("<ul>");
        for (int i = 1; i <= health; i++) {
            result.append("<li><img src=\""+Constants.HEART+"\"></li>");
        }
        for (int i = health; i < totalHealth; i++) {
            result.append("<li><img src=\""+Constants.HEART_BLACK+"\"></li>");
        }
        result.append("</ul>");
        return result.toString();
    }

    public int getHealth() {
        return health;
    }

    public int getMovement() {
        return movement;
    }

    public void lowerMovement() {
        if (movement > 0) --movement;
    }

    public void lowerMovementBy3() {
        movement = movement > 3 ? movement - 3 : 0;
    }

    public void die() {
        health = 0;
        movement = 0;
    }

    public void revive() {
        health = totalHealth;
        movement = totalMovement;
    }
    
    public void lowerHealth() {
        if (health > 0) --health;
    }

    void setDefaults() {
        movement = DEFAULT_MOVEMENT;
        health = DEFAULT_HEALTH;
        totalHealth = DEFAULT_HEALTH;
        totalMovement = DEFAULT_MOVEMENT;
        alreadyExitedRoomThisTurn = false;
    }

    public void endTurn() {
        movement = 0;
    }

    public boolean isAlreadyExitedRoomThisTurn() {
        return alreadyExitedRoomThisTurn;
    }

    public void setAlreadyExitedRoomThisTurn(boolean alreadyExitedRoomThisTurn) {
        this.alreadyExitedRoomThisTurn = alreadyExitedRoomThisTurn;
    }

    public boolean isOutOfMoves() {
        return movement == 0;
    }

    public void resetMovement() {
        movement = totalMovement;
    }
    
}
